import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import '@/assets/styles/nprogress.less'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/pages/Home')
  },
  {
    path: '/passport/signin',
    name: 'SignIn',
    component: () => import('@/pages/Passport/Signin')
  },
  {
    path: '/suit/:alias/reserve',
    name: 'ReserveSuit',
    component: () => import('@/pages/Reserve/Suit')
  },
  {
    path: '/checkout/',
    name: 'CheckoutRoute',
    children: [
      {
        path: 'shipping-init',
        name: 'Shipping',
        component: () => import('@/pages/Checkout/Shipping')
      },
      {
        path: 'billing-init',
        name: 'Billing',
        component: () => import('@/pages/Checkout/Billing')
      },
      {
        path: 'review',
        name: 'Review',
        component: () => import('@/pages/Checkout/Review')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior: (to, from, savedPosition) => {
    return { top: 0 }
  }
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router